<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>Database - Query Builder Where - Fuel Documentation</title>
	<link href="../../assets/css/main.css" media="screen" rel="stylesheet" />
	<script type="text/javascript" src="../../assets/js/jquery-1.4.4.min.js"></script>
	<script type="text/javascript" src="../../assets/js/nav.js"></script>
	<script type="text/javascript" src="../../assets/js/highlight.pack.js"></script>
	<script type="text/javascript">
		$(function() {
			show_nav('classes', '../../');
		});
		hljs.tabReplace = '    ';
		hljs.initHighlightingOnLoad();
	</script>
</head>
<body>

	<header>
		<h1>Fuel Documentation</h1>
	</header>

	<div id="main-nav"></div>

	<section id="content">
		<h2 id="introduction">Query_Builder_Where class</h2>
		
		<p>
			The <strong>Query_Builder_Where</strong> class handles the conditioning and limiting logic for quiry building.
			Every kind of where statement (including BETWEEN and IN etc...) is handled here. This class is not instantiated (it's
			abstract) but extended by other classes that share the same functions. There classes are:
		</p>
		
		<ul>
			<li><a href="qb_select.html">Query_Builder_Select</a></li>
			<li><a href="qb_update.html">Query_Builder_Update</a></li>
			<li><a href="qb_delete.html">Query_Builder_Delete</a></li>
		</ul>
		
		<p id="returned_instance" class="note">
			<strong>Please note:</strong> Since Query_Builder_Where is get extended by the classes listed above, the "current instance" returned will be one of those.
		</p>
		
		<h2 id="methods">Methods</h2>
		
		<article>
			<h4 id="method_where">where()</h4>
			<p>The <strong>where</strong> method is an alias for <a href="#method_and_where">and_where</a>.</p>
		</article>

		<article>
			<h4 id="method_and_where">and_where($column, $op = null, $value = null)</h4>
			<p>The <strong>and_where</strong> method appends a WHERE statement.</p>
			<table class="method">
				<tbody>
					<tr>
						<th>Static</th>
						<td>No</td>
					</tr>
					<tr>
						<th>Parameters</th>
						<td>
							<table class="parameters">
								<tr>
									<th>Param</th>
									<th>Type</th>
									<th>Default</th>
									<th class="description">Description</th>
								</tr>
								<tr>
									<th><kbd>$column</kbd></th>
									<td><em>string</em></td>
									<td><em>required</em></td>
									<td>Column name or array($column, $alias) or object</td>
								</tr>
								<tr>
									<th><kbd>$op</kbd></th>
									<td><em>string</em></td>
									<td><pre class="php"><code>null</code></pre></td>
									<td>Logic operator: =, !=, IN, BETWEEN and LIKE. If none is profided this will fallback to '='</td>
								</tr>
								<tr>
									<th><kbd>$value</kbd></th>
									<td><em>string</em></td>
									<td><pre class="php"><code>null</code></pre></td>
									<td>Column value</td>
								</tr>
							</table>
						</td>
					</tr>
					<tr>
						<th>Returns</th>
						<td>Returns the <a href="#returned_instance">current instance</a>.</td>
					</tr>
					<tr>
						<th>Example</th>
						<td>
							<pre class="php"><code>// prepare a select statement
$query = DB::select('*')->from('users');

// Set the first where statement
$query->where('name', '!=', 'John');

// and append a new condition
$query->and_where('surname', 'Doe');

// Resulting in: SELECT * FROM `users` WHERE `name` != "John" AND `surname` = "Doe"
</code></pre>
						</td>
					</tr>
				</tbody>
			</table>
		</article>
		
		<article>
			<h4 id="method_or_where">or_where($column, $op = null, $value = null)</h4>
			<p>The <strong>or_where</strong> method appends an OR WHERE statement.</p>
			<table class="method">
				<tbody>
					<tr>
						<th>Static</th>
						<td>No</td>
					</tr>
					<tr>
						<th>Parameters</th>
						<td>
							<table class="parameters">
								<tr>
									<th>Param</th>
									<th>Type</th>
									<th>Default</th>
									<th class="description">Description</th>
								</tr>
								<tr>
									<th><kbd>$column</kbd></th>
									<td><em>string</em></td>
									<td><em>required</em></td>
									<td>Column name or array($column, $alias) or object</td>
								</tr>
								<tr>
									<th><kbd>$op</kbd></th>
									<td><em>string</em></td>
									<td><pre class="php"><code>null</code></pre></td>
									<td>Logic operator: =, !=, IN, BETWEEN. If none is profided this will fallback to '='</td>
								</tr>
								<tr>
									<th><kbd>$value</kbd></th>
									<td><em>string</em></td>
									<td><pre class="php"><code>null</code></pre></td>
									<td>Column value</td>
								</tr>
							</table>
						</td>
					</tr>
					<tr>
						<th>Returns</th>
						<td>Returns the <a href="#returned_instance">current instance</a>.</td>
					</tr>
					<tr>
						<th>Example</th>
						<td>
							<pre class="php"><code>// prepare a select statement
$query = DB::select('*')->from('users');

// Set the first where statement
$query->where('name', '=', 'John');

// and append a new condition
$query->or_where('surname', 'Doe');

// Resulting in: SELECT * FROM `users` WHERE `name` != "John" OR `surname` = "Doe"
</code></pre>
						</td>
					</tr>
				</tbody>
			</table>
		</article>
		
		<article>
			<h4 id="method_where_open">where_open()</h4>
			<p>The <strong>where_open</strong> method is an alias for <a href="#method_and_where_open">and_where_open</a>.</p>
		</article>
		
		<article>
			<h4 id="method_and_where_open">and_where_open()</h4>
			<p>The <strong>and_where_open</strong> method opens an SQL closure and appends it using AND.</p>
			<table class="method">
				<tbody>
					<tr>
						<th>Static</th>
						<td>No</td>
					</tr>
					<tr>
						<th>Parameters</th>
						<td>
							<em>None</em>
						</td>
					</tr>
					<tr>
						<th>Returns</th>
						<td>Returns the <a href="#returned_instance">current instance</a>.</td>
					</tr>
					<tr>
						<th>Example</th>
						<td>
							<pre class="php"><code>// prepare a select statement
$query = DB::select('*')->from('users');

// Set a where statement
$query->where('name', 'john');

// Open a closure
$query->and_where_open();

// SELECT * FROM `users` WHERE `name` = "John" AND (
</code></pre>
						</td>
					</tr>
				</tbody>
			</table>
		</article>
		
		<article>
			<h4 id="method_or_where_open">or_where_open()</h4>
			<p>The <strong>or_where_open</strong> method opens an SQL closure and appends it using OR.</p>
			<table class="method">
				<tbody>
					<tr>
						<th>Static</th>
						<td>No</td>
					</tr>
					<tr>
						<th>Parameters</th>
						<td>
							<em>None</em>
						</td>
					</tr>
					<tr>
						<th>Returns</th>
						<td>Returns the <a href="#returned_instance">current instance</a>.</td>
					</tr>
					<tr>
						<th>Example</th>
						<td>
							<pre class="php"><code>// prepare a select statement
$query = DB::select('*')->from('users');

// Set a where statement
$query->where('name', 'john');

// Open a closure
$query->or_where_open();

// SELECT * FROM `users` WHERE `name` = "John" OR (
</code></pre>
						</td>
					</tr>
				</tbody>
			</table>
		</article>
		
		<article>
			<h4 id="method_where_close">where_close()</h4>
			<p>The <strong>where_close</strong> method is an alias for <a href="#method_and_where_close">and_where_close</a>.</p>
		</article>
		
		<article>
			<h4 id="method_and_where_close">and_where_close()</h4>
			<p>The <strong>and_where_close</strong> method closes an SQL closure.</p>
			<table class="method">
				<tbody>
					<tr>
						<th>Static</th>
						<td>No</td>
					</tr>
					<tr>
						<th>Parameters</th>
						<td>
							<em>None</em>
						</td>
					</tr>
					<tr>
						<th>Returns</th>
						<td>Returns the <a href="#returned_instance">current instance</a>.</td>
					</tr>
					<tr>
						<th>Example</th>
						<td>
							<pre class="php"><code>// prepare a select statement
$query = DB::select('*')->from('users');

// Set a where statement
$query->where('email', 'like', '%@example.com');

// Open a closure
$query->and_where_open();

// Set a where statement
$query->where('name', 'John');
$query->or_where('surname', 'Doe');

$query->and_where_close();
// SELECT * FROM `users`
// WHERE `email` LIKE "%example.com" AND (`name` = "John" OR `surname` = "Doe")
</code></pre>
						</td>
					</tr>
				</tbody>
			</table>
		</article>
		
		<article>
			<h4 id="method_or_where_close">or_where_close()</h4>
			<p>The <strong>or_where_close</strong> method closes an SQL closure.</p>
			<table class="method">
				<tbody>
					<tr>
						<th>Static</th>
						<td>No</td>
					</tr>
					<tr>
						<th>Parameters</th>
						<td>
							<em>None</em>
						</td>
					</tr>
					<tr>
						<th>Returns</th>
						<td>Returns the <a href="#returned_instance">current instance</a>.</td>
					</tr>
					<tr>
						<th>Example</th>
						<td>
							<pre class="php"><code>// prepare a select statement
$query = DB::select('*')->from('users');

// Set a where statement
$query->where('email', 'like', '%@example.com');

// Open a closure
$query->or_where_open();

// Set a where statement
$query->where('name', 'John');
$query->and_where('surname', 'Doe');

$query->or_where_close();
// SELECT * FROM `users` WHERE `email` LIKE "%example.com" OR (`name` = "John" AND `surname` = "Doe")
</code></pre>
						</td>
					</tr>
				</tbody>
			</table>
		</article>
		
		<article>
			<h4 id="method_order_by">order_by($column, $direction = NULL)</h4>
			<p>The <strong>order_by</strong> method sets the order for the result/execution.</p>
			<table class="method">
				<tbody>
					<tr>
						<th>Static</th>
						<td>No</td>
					</tr>
					<tr>
						<th>Parameters</th>
						<td>
							<table class="parameters">
								<tr>
									<th>Param</th>
									<th>Type</th>
									<th>Default</th>
									<th class="description">Description</th>
								</tr>
								<tr>
									<th><kbd>$column</kbd></th>
									<td><em>string</em></td>
									<td><em>required</em></td>
									<td>Column name</td>
								</tr>
								<tr>
									<th><kbd>$direction</kbd></th>
									<td><em>string</em></td>
									<td><em>null</em></td>
									<td>Can be set to <em>'asc'</em> or <em>'desc'</em>. Ommit for </td>
								</tr>
							</table>
						</td>
					</tr>
					<tr>
						<th>Returns</th>
						<td>Returns the <a href="#returned_instance">current instance</a>.</td>
					</tr>
					<tr>
						<th>Example</th>
						<td>
							<pre class="php"><code>// prepare a select statement
$query = DB::select('*')->from('users');

// Set the order by
$query->order_by('name');
$query->order_by('email', 'asc');
$query->order_by('surname', 'desc');

// SELECT * FROM `users` ORDER BY `name`, `email` ASC, `surname DESC
</code></pre>
						</td>
					</tr>
				</tbody>
			</table>
		</article>
		
		<article>
			<h4 id="method_limit">limit($number)</h4>
			<p>The <strong>limit</strong> method limits the number of rows selected/affected.</p>
			<table class="method">
				<tbody>
					<tr>
						<th>Static</th>
						<td>No</td>
					</tr>
					<tr>
						<th>Parameters</th>
						<td>
							<table class="parameters">
								<tr>
									<th>Param</th>
									<th>Type</th>
									<th>Default</th>
									<th class="description">Description</th>
								</tr>
								<tr>
									<th><kbd>$number</kbd></th>
									<td><em>int</em></td>
									<td><em>required</em></td>
									<td>The number of rows</td>
								</tr>
							</table>
						</td>
					</tr>
					<tr>
						<th>Returns</th>
						<td>Returns the <a href="#returned_instance">current instance</a>.</td>
					</tr>
					<tr>
						<th>Example</th>
						<td>
							<pre class="php"><code>// prepare a select statement
$query = DB::select('*')->from('users');

// Set the limit
$query->limit(10);

// SELECT * FROM `users` LIMIT 10
</code></pre>
						</td>
					</tr>
				</tbody>
			</table>
		</article>
		
	</section>

	<section id="footer">
		<p>
			<a href="http://fuelphp.com">Fuel</a> is released under the MIT license.<br />
			&copy; 2010 - 2011 Fuel Development Team
		</p>
	</section>

</body>
</html>
